﻿using System.Collections.Generic;
using System.Linq;
using Natural.Model;
using Natural.Attributes;
using Natural.Helpers;

namespace Natural.Providers
{  
    public sealed class Data
    {
        public static List<object[]> Query(Expression expression)
        {
            return Manager.Query(expression);
        }
        public static T First<T>(Expression expression) where T : class
        {
            if (expression.Page == null) expression.Page = new Page() { Number = 1, Size = 1 };
            return Get<T>(expression).FirstOrDefault();
        }
        public static T[] Get<T>(Expression expression)
        {
            return Manager.Get<T>(expression);
        }
        public static void Update<T>(T entity, string includes = null) where T : class
        {
            Manager.Update<T>(entity, includes);
        }
        public static void Delete<T>(T entity, string includes = null) where T : class
        {
            Manager.Delete<T>(entity, includes);
        }

        private static IData Manager
        {
            get { return Solver.Solve("Data") as IData; }
        }
    }
}
